<template>
  <div class="web-main">
    <!--功能-->
    <el-row class="web-header">
      <el-col :span="16">
        <!--<el-button type="primary" @click="editBtn('新增',selectOneRow,'make')">供应商新增</el-button>-->
      </el-col>
      <!--<el-col :span="8" style="text-align: right">-->
        <!--<el-input style="width: 180px" v-model="page.condition.fleetId" @keyup.enter.native="search" placeholder="编号"></el-input>-->
        <!--<el-button type="primary" @click="moreSearch">-->
          <!--<span v-if="!searchFlag">更多</span>-->
          <!--<span v-else>收起</span>-->
        <!--</el-button>-->
      <!--</el-col>-->
    </el-row>
    <!--查询条件-->
    <el-form class="web_form" :inline="true" :class="{'web_form_active': searchFlag }" label-width="140px" style="margin: 6px 0 0 10px">
      <el-form-item label="车架号">
        <el-input v-model="page.condition.vin"  clearable placeholder="请输入" style="width: 184px"></el-input>
      </el-form-item>
      <el-form-item label="车牌号">
        <el-input v-model="page.condition.plateLicenseNo"  clearable placeholder="请输入" style="width: 184px"></el-input>
      </el-form-item>
      <el-form-item label="企业名称">
        <el-input v-model="page.condition.companyName"  clearable placeholder="请输入" style="width: 184px"></el-input>
      </el-form-item>
      <el-form-item label="司机名称">
        <el-input v-model="page.condition.driverName"  clearable placeholder="请输入" style="width: 184px"></el-input>
      </el-form-item>
      <el-form-item label="所属地">
        <el-cascader
          class="w184"
          placeholder="任意搜索地区"
          :options="areaData"
          filterable
          change-on-select
          @change="startAddressChange"
          v-model="selectedOptionsStart"
        ></el-cascader>
      </el-form-item>
      <!--<el-form-item label="创建时间">-->
        <!--<el-date-picker class="w184"-->
                        <!--v-model="page.condition.startDate"-->
                        <!--type="datetime"-->
                        <!--value-format = 'yyyy-MM-dd HH:mm:ss'-->
                        <!--placeholder="选择日期">-->
        <!--</el-date-picker>- -->
        <!--<el-date-picker class="w184"-->
                        <!--v-model="page.condition.endDate"-->
                        <!--type="datetime"-->
                        <!--value-format = 'yyyy-MM-dd HH:mm:ss'-->
                        <!--placeholder="选择日期">-->
        <!--</el-date-picker>-->
      <!--</el-form-item>-->
      <el-form-item class="search-box">
        <el-button type="primary" @click="search">查询</el-button>
        <el-button type="primary" @click="resetSearch">重置</el-button>
      </el-form-item>
    </el-form>
    <!--主列表-->
    <div style="width: 100%;position: relative;">
      <el-table
        :data="tableData"
        ref="mainTable"
        header-row-class-name="table-header-center"
        border element-loading-text="正在加载中..."
        @selection-change="handleSelectionChange"
        style="margin: 0 4px;">
        <el-table-column type="selection" width="40"></el-table-column>
        <el-table-column type="index" label="序号" width="50"></el-table-column>
        <el-table-column :key="key" align="center" :width="value.width" v-for='(value,key) in tableHead'
                         :label="value.title">
          <template slot-scope="scope">
            <!--<div v-if="value.filter">{{scope.row[value.key] | geval(value.filter)}}</div>-->
            <!--<a v-if="value.key === 'no'" href="#" @click="handleLook(scope.row)" style="color: #409EFF; font-size: 12px;">{{scope.row.no}}</a>-->
            <div v-if="value.key === 'gmtCreate'">{{scope.row.gmtCreate | parseTime('{y}-{m}-{d} {h}:{i}:{s}')}}</div>
            <div v-else-if="value.key === 'status'">{{scope.row.status | statusFilter}}</div>
            <div v-else>{{scope.row[value.key]}}</div>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="100" fixed="right">
          <template slot-scope="scope">
            <el-button type="text" size="mini" @click="toChartsShow('查看',scope.row,'carSituationChartsShow')">查看</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 分页 -->
    <el-pagination
      style="margin-top: 8px"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="page.current"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="page.size"
      layout="total, sizes, prev, pager, next, jumper"
      :total="page.total">
    </el-pagination>
    <!-- 占位 -->
    <div style="height: 50px"></div>
  </div>
</template>

<script>
  import Area from '@/utils/area/index'
  import * as Utils from '@/utils/index'
  import * as monitorMgtAPI from '@/api/monitor'
  // import * as Utils from '@/utils/index'
  const defaultTableHead = [
    { key: 'vin', title: '车架号', width: '150' },
    { key: 'plateLicenseNo', title: '车牌号', width: '' },
    { key: 'province', title: '所在省份', width: '' },
    { key: 'city', title: '所在城市', width: '' },
    { key: 'county', title: '所在城区', width: '150' },
    { key: 'company', title: '所属企业', width: '150' },
    { key: 'driver', title: '所属司机', width: '150' },
    { key: 'status', title: '车辆状态', width: '150', filter: 'statusFilter' },
    { key: 'gmtCreate', title: '创建时间', width: '150', filter: 'parseTime("{y}-{m}-{d} {h}:{i}:{s}")' }
  ]
  export default {
    name: '',
    components: { },
    data() {
      return {
        tableHead: defaultTableHead,
        searchFlag: true,
        tableData: [],
        selectRow: [],
        selectOneRow: {},
        page: { current: 1, size: 10, total: 1,
          condition: {
            plateLicenseNo: '',
            driverName: '',
            companyName: '',
            vin: '',
            city: '',
            county: '',
            province: ''
          }
        },
        areaData: Area, // 省-市-区三级联动选择
        selectedOptionsStart: ['广东省', '深圳市', '南山区']
      }
    },
    created() {
      this.getList()
    },
    methods: {
      // 三级连选 起运地地址
      startAddressChange(val) {
        const selectArr = val
        console.log('startAddressChange()-val', val)
        this.selectArea = Utils.areaCode2AreaName(selectArr)
        console.log('startAddressChange()-res_obj', this.selectArea)
        const { province, city, area } = this.selectArea
        this.page.condition.province = province
        this.page.condition.city = city
        this.page.condition.county = area
      },
      toChartsShow(ditTitle, row, val) {
        // sessionStorage.removeItem('carSituationSelectRow')
        // console.log('toChartsShow()-val查看', val)
        // this.$router.push({ path: '/vendor/monitor/' + val })
        // sessionStorage.setItem('carSituationSelectRow', JSON.stringify(row))
        // this.$router.push({ name: val, params: { row: row }})
        this.$router.push({ path: '/vendor/monitor/' + val, query: { row: row }})
      },
      // 禁用
      statusBtn() {
      },
      // 启用
      enableBtn() {
      },
      // 列表查询
      getList() {
        const that = this
        monitorMgtAPI.vehiclesGetVehiclesList(that.page).then(res => {
          const t = res.data
          that.tableData = t.records
          that.page.current = t.current
          that.page.size = t.size
          that.page.total = t.total
        }).catch(err => {
          console.log('error', err)
        })
      },
      // 更多
      moreSearch() {
        this.searchFlag = !this.searchFlag
      },
      // 查询
      search() {
        this.page.current = 1
        this.page.size = 10
        this.getList()
      },
      handleSizeChange(val) {
        this.page.size = val
        this.page.current = 1
        this.getList()
      },
      handleCurrentChange(val) {
        this.page.current = val
        this.getList()
      },
      // 重置
      resetSearch() {
        this.page.current = 1
        this.page.size = 10
        this.page.condition = {
          plateLicenseNo: '',
          driverName: '',
          companyName: '',
          vin: '',
          city: '',
          county: '',
          province: ''
        }
        this.selectedOptionsStart = ['广东省', '深圳市', '南山区']
        this.getList()
      },
      // 检查是否选择单条
      checkSelect(data) {
        const l = data.length
        if (l === 0) {
          this.$message({
            message: '未选择',
            type: 'warning',
            duration: 2000
          })
          return false
        }
        return true
      },
      // 表格改变时
      handleSelectionChange(val) {
        this.selectRow = val
      }
    }
  }
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  .web_form.webForm_active{
    height: auto;
  }
</style>
